package com.yunti.springboot.vo.res;

import com.yunti.springboot.po.Score;
import com.yunti.springboot.po.SubItem;
import lombok.Data;

import java.util.Comparator;
import java.util.List;

@Data
public class SubItemRes extends SubItem {
    private Score finalScore;
    private List<Score> scoreList;

    public void setScoreList(List<Score> scoreList) {
        this.scoreList = scoreList;
        this.scoreList.stream().max(new Comparator<Score>() {
            @Override
            public int compare(Score o1, Score o2) {
                Double score1 = Double.MIN_NORMAL;
                Double score2 = Double.MIN_NORMAL;
                if(o1.getConversionScore()!=null){
                    score1 = o1.getConversionScore().doubleValue();
                }
                if(o2.getConversionScore()!=null){
                    score2 = o2.getConversionScore().doubleValue();
                }
                return Double.compare(score1, score2);
            }
        }).ifPresent(finalScore -> {
            this.finalScore = finalScore;
        });
    }
}
